import log from '@dfeidao/atom-nodejs/logger/log';
import { IncomingHttpHeaders } from 'http';
import query from '@dfeidao/atom-nodejs/db/query';
import { systemid, productid } from '../../atom/config';
import count from '@dfeidao/atom-nodejs/db/count';
interface Message {
	page_no: number,
	post_name: string

}

// interface IWebResult {
// 	data: unknown;
// 	cookie?: {
// 		[name: string]: string;
// 	} | null;
// 	content_type?: string;
// 	headers?: {
// 		[key: string]: string[];
// 	};
// 	attachment?: string;
// 	redirect?: string;
// 	status_code?: number;
// }

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders) {
	const { prepare, exec } = query(action_id, session_id, systemid);
	prepare('post', ['post_no', 'post_name', 'productid', 'post_function'], { productid, post_name: { $like: '%' + message.post_name + '%' } }, 2, message.page_no, [], []);
	const [data] = await exec();
	const { prepare: p, exec: e } = count(action_id, session_id, systemid)
	p('post', { productid, post_name: { $like: '%' + message.post_name + '%' } });
	const [x] = await e();
	return {
		data: { data, x }
	}
}
